<template>
  <div id="mTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="消息类型" prop="messageTemplateAlias">
          <el-select
            v-model="formInline.messageTemplateAlias"
            clearable
            filterable
          >
            <el-option
              v-for="(item, index) in statusList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="发送渠道" prop="sendType">
          <el-select v-model="formInline.sendType" clearable filterable>
            <el-option
              v-for="(item, index) in channeList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" @click="resetSearch" plain>
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'mTopSearch',
  msg: '顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          messageTemplateAlias: '', // 消息类型
          sendType: '' // 发送渠道
        }
      }
    }
  },

  data() {
    return {
      loading: true,
      // 消息类型
      statusList: [{ dictLabel: '全部', dictValue: '' }],
      // 渠道
      channeList: [{ dictLabel: '全部', dictValue: '' }]
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 获取字典状态 */
    async getStatusList() {
      let data = await sysNormalDisable(
        'system_message_template_alias',
        'system_message_template_alias'
      )
      this.statusList = this.statusList.concat(data)
      let datachanneList = await sysNormalDisable('send_type', 'send_type')
      this.channeList = this.channeList.concat(datachanneList)
    },

    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },

    /** 重置搜索条件 */
    resetSearch() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang="less">
#mTopSearch {
  .long-input {
    .el-input--suffix {
      width: 130px !important;
    }
  }
}
</style>
